from selenium.webdriver.common.by import By


from po_study.base.Base import Base
from po_study.utils.Logger import Logger

logger = Logger('GoodsListPage').getlog()

class GoodsListPage(Base):
    def __init__(self, driver):
        Base.__init__(self, driver)

    def into_menu_frame(self):
        self.into_frame('menu-frame')
        logger.info('光标进入菜单内帧')

    def into_main_frame(self):
        self.into_frame('main-frame')
        logger.info('光标进入主内帧')

    def click_good_list(self):
        self.click((By.LINK_TEXT, '商品列表'))
        logger.info('点击菜单列表')

    # 输入搜索框 ‘华为’
    def input_search_text(self):
        self.input((By.NAME, 'keyword'), '华为')
        logger.info('点击菜单列表')

    # 点击搜索按钮
    def click_search_button(self):
        self.click((By.XPATH, '/html/body/div[3]/form/input[2]'))
        logger.info('点击搜索按钮')

    # 选择销售状态（新品）
    def select_by_type(self):
        self.select_by_text((By.NAME, 'intro_type'), "新品")
        logger.info('选择销售状态（新品）')

    # 点击菜单列表
    def add_new_good(self):
        self.click((By.LINK_TEXT, '添加新商品'))
        logger.info('点击菜单列表')

    # 商品名称输入框输入“联想笔记本”
    def input_good_name(self):
        self.input((By.NAME, 'goods_name'), '联想笔记本')
        logger.info('商品名称输入框输入“联想笔记本”')

    # 搜索的个数
    def get_search_count(self):
        return self.get_text((By.XPATH, '//*[@id="totalRecords"]'))

    # 选择 商品分类
    def select_good_by_type(self):
        self.select_by_text((By.NAME, 'cat_id'), "        平板电脑")
        logger.info('选择 商品分类')

    #  添加列表 点击确定
    def click_sure(self):
        self.click((By.XPATH, '//*[@id="tabbody-div"]/form/div/input[2]'))
        logger.info('添加列表 点击确定')

    # 点击√
    def click_is_or_no(self):
        self.click((By.XPATH, '//*[@id="listDiv"]/table[1]/tbody/tr[3]/td[5]'))
        logger.info('点击√')